<?php

namespace App\Web\Data;

class Data_ScrumSprint extends \Lib\Data {
    function __construct() {
        parent::__construct();
    }

    public function getTableName() {
        return 'scrum_sprints';
    }

    /**
     * 获取最近的冲刺
     *
     * @date   2018-07-31
     * @return mixed
     */
    public function getLastSprintInfo() {
        $sql = "SELECT * FROM " . $this->getTableName() . " ORDER BY id DESC";
        $this->prepare($sql);
        $ret = $this->single();
        return $ret;
    }

    /**
     * 获取信息
     *
     * @date   2018-07-31
     * @param int $sid
     * @return mixed
     */
    public function getSprintsInfoBySid($sid) {
        $sql = "SELECT * FROM " . $this->getTableName() . " WHERE id = :id";
        $this->prepare($sql);
        $this->bind(':id', $sid);
        $ret = $this->single();

        return $ret;
    }

    /**
     * 获取冲刺列表
     *
     * @date   2018-07-31
     * @param int $offset
     * @param int $limit
     * @return mixed
     */
    public function getSprintsList($offset = 0, $limit = 50) {
        $sql = "SELECT * FROM " . $this->getTableName() . " order by id desc limit {$offset}, {$limit} ";
        $this->prepare($sql);

        $ret = $this->results();

        return $ret;
    }

    /**
     * 添加
     *
     * @date   2018-08-01
     * @param array $data
     * @return array
     */
    public function addRow($data) {
        $ret = [];
        if (empty($data)) {
            return $ret;
        }

        $ret = $this->insertRow($data);

        return $ret;
    }

    /**
     * 修改
     *
     * @date   2018-08-01
     * @param array $where
     * @param array $data
     * @return array
     */
    public function editRowById($where, $data) {
        $ret = [];
        if (empty($where) || empty($data)) {
            return $ret;
        }

        $ret = $this->edit($where, $data);

        return $ret;
    }


    /**
     * 修改
     *
     * @date   2018-08-01
     * @param array $where
     * @return bool
     */
    public function delRowById($where) {
        $ret = [];
        if (empty($where)) {
            return $ret;
        }

        $ret = $this->delete($where);

        return $ret;
    }
}